package ai.汉诺塔;

import java.util.Iterator;
import java.util.Stack;

//汉诺塔中的一个塔
public class Tower {
    //塔栈
    private Stack<Integer> tower;

    //塔名字
    private String name;

    Tower(String name, Stack<Integer> tower) {
        this.name = name;
        this.tower = tower;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Stack<Integer> getTower() {
        return tower;
    }

    public void setTower(Stack<Integer> tower) {
        this.tower = tower;
    }

    //一个盘子的界面绘制
    private String draw(int n) {
        StringBuilder builder = new StringBuilder();

        for (int i = 0;i<n;i++){
            builder.append("=");
        }

        return builder.toString();
    }

    //toString()画出整个盘
    @Override
    public String toString() {
        Iterator<Integer> i = tower.iterator();
        Stack<Integer> temp = (Stack<Integer>) tower.clone();
        StringBuilder builder = new StringBuilder();
        builder.append("<html>");

        while (!temp.isEmpty()){
            builder.append("<p text-align=\"center\" color=\"RED\">").append(draw(temp.pop())).append("</p>");
        }
        builder.append("</html>");
        return builder.toString();
    }
}
